/*
 *  common.c
 *  EcouteurClavier
 *
 *  Created by jihed kamkoum on 27/04/10.
 *  Copyright 2010 ENSEIRB. All rights reserved.
 *
 */

#include "common.h"

buffer_t *create_buffer(char * data, int len){
	buffer_t *buf = NULL;
	buf = malloc(sizeof(buffer_t));
	if (buf == NULL)
		return NULL;
	
	buf->data = data;
	buf->len = len;
	return buf;
}

return_t destroy_buffer(buffer_t *buf){
	if (buf != NULL){
		if (buf->data != NULL)
			free(buf->data);
		free(buf);
		return RT_OK;
	}
	return RT_ERR;
}


void print_addr(SOCKADDR_IN  *addr){
	fprintf(stdout, "(ip:port) %s:%d\n",
			inet_ntoa(addr->sin_addr), htons(addr->sin_port));
}